package com.yesep.learn.design.behavioral.chain_of_responsibility.impl.leave;

import com.yesep.learn.design.common.util.*;
import com.yesep.learn.design.behavioral.chain_of_responsibility.engine.*;

import java.time.*;

/**
 * 请假业务对象
 */
public class LeaveRequest implements IChainRequest {
    /**
     * 请假人
     */
    private ChainActor actor;


    /**
     * 开始时间
     */
    private LocalDateTime begin;
    /**
     * 结束时间
     */
    private LocalDateTime end;


    /**
     * 当前处理节点编号
     */
    private String handlerKey;

    public LeaveRequest(ChainActor actor, LocalDateTime begin, LocalDateTime end) {
        this.actor = actor;
        this.begin = begin;
        this.end = end;
        this.handlerKey = LeaveStartHandler.class.getName();
    }

    @Override
    public ChainActor getActor() {
        return actor;
    }

    public void setActor(ChainActor actor) {
        this.actor = actor;
    }

    public LocalDateTime getBegin() {
        return begin;
    }

    public void setBegin(LocalDateTime begin) {
        this.begin = begin;
    }

    public LocalDateTime getEnd() {
        return end;
    }

    public void setEnd(LocalDateTime end) {
        this.end = end;
    }

    public double getDays() {
        return Util.getDaysBetween(getBegin(), getEnd());
    }


    @Override
    public String getHandlerKey() {
        return handlerKey;
    }

    public void setHandlerKey(String handlerKey) {
        this.handlerKey = handlerKey;
    }

    @Override
    public String toString() {
        return String.format("LeaveRequest{userId='%s', userName='%s', begin='%s', end='%s', days='%s', handler='%s'}",
                actor.getUserId(), actor.getUserName(), begin, end, getDays(), handlerKey);
    }
}
